﻿Imports System.Data
Imports ADOEntityKYC
Imports ADOEntityAMLO1059
Imports ADOEntity

Partial Class AMLO_SearchAmlo1_05_9
    Inherits Web.UI.BasePage
    Private Const strMenuCode As String = "M57"
    Dim dsAmlo As DataSet
    Dim clsDataTable As clsLINQToDataTable
    Dim AMLOEntity As AMLO1059Entities
    Dim intBeforeItemIndex As Integer
    Dim clsSessionMenuRight As clsSessionMenuRight
    Dim clsFormatDate As clsDateFormat
    Dim clsMasterDropDown As clsMasterDropDown

#Region "Even From "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        chkIsLogin()
        btnSearch.Attributes.Add("onclick", "NoDoubleSubmit();")
        btnDelete.OnClientClick = "return confirm('ต้องการลบข้อมูล');"
        If (Not IsPostBack) Then

            AMLOEntity = New AMLO1059Entities
            clsMasterDropDown = New clsMasterDropDown
            clsSessionMenuRight = Session("ClsMenuRight")
            dsAmlo = New DataSet()
            CreateControlMP()
            loadDropDown()
            setUserRightButton()
            setDefaultSearch()

            AMLOEntity.Dispose()
            AMLOEntity = Nothing
        Else
            dsAmlo = Session("ds")
            'grdAmlo.DataSource = dsAmlo.Tables("Amlo")
            'grdAmlo.DataBind()
        End If

    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        Session("ds") = dsAmlo
    End Sub
#End Region

#Region "SetForm"

    Sub resourceSet()

    End Sub
#End Region

#Region "Even Button"
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        IsDataBind()
        SaveLogSearch()
        clearGvIndex()
    End Sub

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Response.Redirect("Amlo1_05_9.aspx")
    End Sub

    Protected Sub btnApprove_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnApprove.Click
        AMLOEntity = New AMLO1059Entities
        AMLOEntity.Connection.Open()
        Using transaction As System.Data.Common.DbTransaction = AMLOEntity.Connection.BeginTransaction()
            Try
                Dim id As String = ""
                Dim isConfirm As String = "0"
                For i As Integer = 0 To grdAmlo.Rows.Count - 1
                    id = CType(grdAmlo.Rows(i).FindControl("hdfRptSeq"), HiddenField).Value
                    isConfirm = CType(grdAmlo.Rows(i).FindControl("rdoUserConfirm"), RadioButtonList).SelectedValue

                    UpdateUserConfirm(id, isConfirm)
                Next
                transaction.Commit()

                'setButton(3)
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('บันทึกเสร็จเรียบร้อยแล้ว')", True)
                IsDataBind()

            Catch ex As Exception
                transaction.Rollback()
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('Error : " & ex.ToString & " Error message : " & ex.Message & "')", True)

            End Try
        End Using
    End Sub

    Protected Sub UpdateUserConfirm(ByVal amloId As String, ByVal confirmFlag As String)
        Try
            Dim qry = (From tblAmlo In AMLOEntity.AMLO1059 Where tblAmlo.ID = amloId).Single
            qry.ISCONFIRM = confirmFlag
            AMLOEntity.SaveChanges()
        Catch ex As Exception
            WriteError(ex, "UpdateUserConfirm", "SearchAmlo1_05_9")
            Throw ex
        End Try
    End Sub
#End Region

#Region "Even GridView"

    Protected Sub grdAmlo_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdAmlo.RowDataBound
        clsFormatDate = New clsDateFormat
        If (e.Row.RowType.ToString = "DataRow") Then
            If Not (e.Row.Cells(4).Text = Nothing) Then
                e.Row.Cells(4).Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, e.Row.Cells(4).Text)
            End If

            Dim rowView = CType(e.Row.DataItem, DataRowView)
            If (Not (rowView("ISCONFIRM") = "0") Or rowView("ISSEND") = "1") Then
                Dim rdoUserConfirm = CType(e.Row.FindControl("rdoUserConfirm"), RadioButtonList)
                rdoUserConfirm.Enabled = False
            End If

            If (rowView("ISSEND") = "1") Then
                Dim chkDel = CType(e.Row.FindControl("CheckBox1"), CheckBox)
                chkDel.Enabled = False
            End If
        End If
    End Sub

    Private Sub EnableBtn(ByVal isSend As String, ByVal isDelete As String)
        If (isSend = "Y") Then
            btnApprove.Enabled = False
            btnDelete.Enabled = False
        Else
            btnApprove.Enabled = True
            btnApprove.Enabled = True
        End If
    End Sub
    Protected Sub grdAmlo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdAmlo.SelectedIndexChanged
        If (grdAmlo.SelectedIndex = intBeforeItemIndex) Then
            clearGvIndex()
        Else
            Dim txtIsSend As String = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("lblIsSend"), Label).Text
            Dim txtIsDelete As String = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("Label11"), Label).Text
            Dim UserRight As clsSessionMenuRight
            UserRight = Session("clsMenuRight")
            If (UserRight.getRoleGroup > 79) Then 'กรณี Admin เข้าระบบมาเพื่อลบ
                If (txtIsDelete = "Y") Then
                    btnDelete.Text = "ยืนยันการลบ"
                    btnDelete.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resValidate.confirmDelete, IIf(grdAmlo.SelectedIndex = -1, "", "")) + "');")
                Else
                    btnDelete.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resValidate.confirmNonReqDelete, IIf(grdAmlo.SelectedIndex = -1, "", "")) + "');")
                End If

            ElseIf (UserRight.getRoleGroup < 80) Then 'กรณี user เข้าระบบมาเพื่อลบ
                If (txtIsDelete = "Y") Then
                    btnDelete.Text = "ยกเลิกลบ"
                    btnDelete.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resValidate.confirmCancelDelete, IIf(grdAmlo.SelectedIndex = -1, "", "")) + "');")
                Else

                    btnDelete.Attributes.Add("onclick", "return confirm('" + String.Format(Resources.resValidate.confirmDelete, IIf(grdAmlo.SelectedIndex = -1, "", "")) + "');")
                End If
            End If
            UserRight = Nothing

            EnableBtn(txtIsSend, txtIsDelete)
        End If
    End Sub

    Protected Sub grdAmlo_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles grdAmlo.SelectedIndexChanging
        intBeforeItemIndex = grdAmlo.SelectedIndex
    End Sub

    Protected Sub grdAmlo_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdAmlo.PageIndexChanging
        grdAmlo.DataSource = dsAmlo.Tables("Amlo")
        grdAmlo.DataBind()

        grdAmlo.PageIndex = e.NewPageIndex
        clearGvIndex()
        DataBind()
    End Sub

    Protected Sub grdAmlo_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdAmlo.Sorting
        Dim dt = TryCast(dsAmlo.Tables("Amlo"), DataTable)

        If dt IsNot Nothing Then

            'Sort the data.
            dt.DefaultView.Sort = e.SortExpression & " " & GetSortDirection(e.SortExpression)
            grdAmlo.DataSource = dsAmlo.Tables("Amlo")
            grdAmlo.DataBind()
            clearGvIndex()
        End If
    End Sub

#End Region

#Region " Function "

    Private Sub SaveLogPrint(ByVal index As Integer)
        Try
            Dim program As String = "M57"
            Dim desc As String = ""
            Dim strUnique As String = "033"

            clsSessionMenuRight = Session("ClsMenuRight")

            If index = 1 Then
                desc = "ค้นหาข้อมูลจาก "
                If Not (ddlBranch.SelectedIndex = 0) Then
                    desc = desc & " ส่วนงาน/สาขา " & ddlBranch.Text
                End If

                If Not (txtDateStart.Text = "" And txtDateEnd.Text = "") Then
                    desc = desc & " วันที่ทำธุรกรรม " & txtDateStart.Text & " ถึง " & txtDateEnd.Text
                End If

                If Not (rdoDelete.SelectedValue = -1) Then
                    desc = desc & " สถานะยันยัน " & rdoDelete.Text
                End If


            Else
                desc = "พิมพ์ฟอร์ม แบบรายงานการทำธุรกรรมที่ใช้เงินสด"
            End If

            Dim strFullNo As String = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("hdfRptFullNo"), HiddenField).Value


            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction(strFullNo.Trim, clsSessionMenuRight.getUserName, index, desc, program)
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub setUserRightButton()
        Dim col As New Collection

        col.Add(btnSearch, statusbtn.Query.ToString)
        'col.Add(btnAdd, statusbtn.Add.ToString)
        col.Add(btnApprove, statusbtn.Modify.ToString)
        col.Add(btnDelete, statusbtn.delete.ToString)
        'col.Add(btnPrint, statusbtn.print.ToString)
        setBtnToUserRight(col, strMenuCode, clsSessionMenuRight.getDsMenuRight)

    End Sub

    Private Sub loadDropDown()
        clsMasterDropDown = New clsMasterDropDown
        If (clsSessionMenuRight.getRoleGroup > 79) Then
            clsMasterDropDown.setBranchDdlSearch(ddlBranch, strDeptCode:="0", _
                                            strBranchCode:=clsSessionMenuRight.getBranchCode, _
                                            strRoleCode:=clsSessionMenuRight.getRoleGroup, _
                                            strZoneCode:=clsSessionMenuRight.getZoneCode, _
                                            selectData:=clsSessionMenuRight.getBranchCode)

        Else
            clsMasterDropDown.setBranchDdlSearch(ddlBranch, strDeptCode:=clsSessionMenuRight.getDeptCode, _
                                                        strBranchCode:=clsSessionMenuRight.getBranchCode, _
                                                        strRoleCode:=clsSessionMenuRight.getRoleGroup, _
                                                        strZoneCode:=clsSessionMenuRight.getZoneCode, _
                                                        selectData:=clsSessionMenuRight.getBranchCode)

        End If
        clsMasterDropDown.setDdlTransType_AMLO1059(ddlTransType)
    End Sub
    Public Sub setDefaultSearch()
        clsFormatDate = New clsDateFormat
        txtDateStart.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)
        txtDateEnd.Text = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.Th, dteDateIsChk:=Date.Now)

        If (clsSessionMenuRight.getRoleGroup > 79) Then
            rdoDelete.Visible = True
            ChkIsDelete.Visible = False
        ElseIf (clsSessionMenuRight.getRoleGroup < 80) Then
            rdoDelete.Visible = False
            ChkIsDelete.Visible = True
        End If

        If (clsSessionMenuRight.getRoleGroup > 59) Then
            ddlBranch.Enabled = True
        ElseIf (clsSessionMenuRight.getRoleGroup < 60) Then
            ddlBranch.Enabled = False
        End If

        rdoDelete.SelectedValue = -1
    End Sub

    Sub CreateControlMP() 'อ้าง control ใน masterPage
        Dim img As Image = CType(Master.FindControl("imgHead"), Image)
        img.ImageUrl = "~/img/ghb_.GIF"
        Dim lbl As Label = CType(Master.FindControl("lblPage"), Label)
        lbl.Text = "ค้นหา ปปง.1-05-9"
    End Sub

    Private Sub IsDataBind()
        AMLOEntity = New AMLO1059Entities
        clsDataTable = New clsLINQToDataTable
        clsFormatDate = New clsDateFormat
        Dim UserRight As clsSessionMenuRight
        UserRight = Session("clsMenuRight")

        If dsAmlo.Tables.Contains("Amlo") Then
            dsAmlo.Tables.Clear()
        End If
        Dim qryAmlo = From tblAmlo In AMLOEntity.AMLO1059 Join tblBranch In AMLOEntity.SBRANCHes _
                      On tblAmlo.INIT_SOL_ID Equals tblBranch.SOL_ID _
                     Group Join tblTran In AMLOEntity.MTSCTYPE_1_05_9 On tblAmlo.KEY_FLG Equals tblTran.TSCTYPEID
                      Into leftJoinAmlo = Group
                      From tblLeftAmlo In leftJoinAmlo.DefaultIfEmpty
                     Order By tblAmlo.ID _
                   Select tblAmlo.RPTREV, tblAmlo.ID, tblAmlo.KEY_FLG, tblAmlo.DCN_YEARMONTH, tblAmlo.DCN_DOCUMENTNO, tblAmlo.P3_TRAN_ID, tblAmlo.P3_TRANS_TYPE, tblAmlo.P3_TRANS_DATE, tblAmlo.P3_TRAN_AMT, tblAmlo.INIT_SOL_ID, _
                   tblAmlo.P2_SALUTATION, tblAmlo.P2_CUST_FNAME, tblAmlo.P2_CUST_MNAME, tblAmlo.P2_CUST_LNAME, _
                   tblAmlo.P2_FORACID2, tblAmlo.P2_SALUTATION2, tblAmlo.P2_CUST_FNAME2, tblAmlo.P2_CUST_MNAME2, tblAmlo.P2_CUST_LNAME2, TSCTYPEID = If(tblLeftAmlo.TSCTYPEID Is Nothing, "-", tblLeftAmlo.TSCTYPEID), _
                   tblAmlo.P3_CUST_NAME, tblAmlo.P3_FORACID, tblAmlo.P3_CUST_NAME2, tblAmlo.P3_FORACID2,
                   tblBranch.DEPTCODE, tblBranch.ZONECODE, tblBranch.BRANCHCODE, _
                   tblAmlo.P3_TRAN_CODE, tblLeftAmlo.TSCTYPENAME, tblAmlo.CREATEBY, tblAmlo.UPDATEBY, tblAmlo.ISCONFIRM, tblAmlo.ISSEND, tblAmlo.ISDELETE, tblAmlo.ISCOMPLETE

        If (UserRight.getRoleGroup > 79) Then 'เป็น admin ระบบ กับ  admin ธนาคาร
            If (rdoDelete.SelectedValue = 1) Then
                'qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISDELETE = 1)
            ElseIf (rdoDelete.SelectedValue = 2) Then
                'wantawin           qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISCONFIRM = 1)
            End If
        ElseIf (UserRight.getRoleGroup < 80) Then 'เป็น admin ฝ่าย ลงมา
            If ChkIsDelete.Checked Then
                'qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISCONFIRM = 0 And tbl_Amlo.ISDELETE = 1)
            Else
                'wantawin          qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISCONFIRM = 0)
            End If

        End If



        If (UserRight.getRoleGroup > 79) Then 'admin ระบบขึ้นไป
            If Not (ddlBranch.SelectedIndex = 0) Then
                qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.BRANCHCODE = ddlBranch.SelectedValue)
            End If
        ElseIf (UserRight.getRoleGroup > 69) Then 'Admin ฝ่าย

            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.DEPTCODE = UserRight.getDeptCode)
        ElseIf (UserRight.getRoleGroup > 59) Then 'Admin เขต 
            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.DEPTCODE = UserRight.getDeptCode And tbl_Amlo.ZONECODE = UserRight.getZoneCode)

        ElseIf (UserRight.getRoleGroup > 49) Then 'Admin สาขา
            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.DEPTCODE = UserRight.getDeptCode And tbl_Amlo.BRANCHCODE = ddlBranch.SelectedValue)

        ElseIf (UserRight.getRoleGroup < 50) Then 'user ทั่วไป
            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.BRANCHCODE.Contains(ddlBranch.SelectedValue) And tbl_Amlo.BRANCHCODE = UserRight.getBranchCode)

        End If



        If Not (ddlBranch.SelectedValue = "0") Then
            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.BRANCHCODE = ddlBranch.SelectedValue)
        End If

        If Not (ddlTransType.SelectedValue = "0") Then
            qryAmlo = qryAmlo.Where(Function(tbl_amlo) tbl_amlo.KEY_FLG = ddlTransType.SelectedValue)
        End If

        If Not (txtDateStart.Text = "" And txtDateEnd.Text = "") Then
            Dim strStartDate As String = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDateStart.Text)
            Dim strEndDate As String = clsFormatDate.chkDateThOrEn(clsDateFormat.enmDateCultureInfo.En, txtDateEnd.Text)
            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.P3_TRANS_DATE >= strStartDate And tbl_Amlo.P3_TRANS_DATE <= strEndDate)
        End If

        If Not (rdoDelete.SelectedValue = -1) Then
            qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISCONFIRM = rdoDelete.SelectedValue)
            'If (rdoDelete.SelectedValue = 1) Then
            '    qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISDELETE = 1)
            'ElseIf (rdoDelete.SelectedValue = 2) Then
            '    qryAmlo = qryAmlo.Where(Function(tbl_Amlo) tbl_Amlo.ISCONFIRM = 1)
            'End If
        End If

        dsAmlo.Tables.Add(clsDataTable.LINQToDataTable(qryAmlo, "Amlo").Copy)
        If (qryAmlo.Count = 0) Then
            lblMsg.Visible = True
            lblTotal.Text = ""
        Else
            lblMsg.Visible = False
            lblTotal.Text = "จำนวนรายการทั้งหมด " + qryAmlo.Count.ToString + " รายการ "
        End If


        grdAmlo.DataSource = dsAmlo.Tables("Amlo")
        grdAmlo.DataBind()
        'txtYear.Text = dsRRPT.Tables("RRPT").Rows(0)("saveDate")

        clsDataTable = Nothing
        AMLOEntity = Nothing

    End Sub
    Private Sub clearGvIndex()
        grdAmlo.SelectedIndex = -1
        btnDelete.Attributes.Clear()
        btnDelete.Text = "ลบ"
    End Sub

    Private Function GetSortDirection(ByVal column As String) As String

        ' By default, set the sort direction to ascending.
        Dim sortDirection = "DESC"

        ' Retrieve the last column that was sorted.
        Dim sortExpression = TryCast(ViewState("SortExpression"), String)

        If sortExpression IsNot Nothing Then
            ' Check if the same column is being sorted.
            ' Otherwise, the default value can be returned.
            If sortExpression = column Then
                Dim lastDirection = TryCast(ViewState("SortDirection"), String)
                If lastDirection IsNot Nothing _
                  AndAlso lastDirection = "DESC" Then

                    sortDirection = "ASC"

                End If
            End If
        End If

        ' Save new values in ViewState.
        ViewState("SortDirection") = sortDirection
        ViewState("SortExpression") = column
        Return sortDirection
    End Function

    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try

            Dim UserRight As clsSessionMenuRight
            UserRight = Session("clsMenuRight")
            If (UserRight.getRoleGroup > 79) Then
                AMLOEntity = New AMLO1059Entities

                For i As Int16 = 0 To grdAmlo.Rows.Count - 1
                    Dim chkrow As CheckBox = CType(grdAmlo.Rows(i).FindControl("CheckBox1"), CheckBox)
                    Dim txtCode As String = CType(grdAmlo.Rows(i).FindControl("hdfRptSeq"), HiddenField).Value
                    Dim txtIsDelete As String = CType(grdAmlo.Rows(i).FindControl("Label11"), Label).Text
                    If (chkrow.Checked) Then
                        Dim qryDelete = (From tblAmlo1059 In AMLOEntity.AMLO1059 Where tblAmlo1059.ID = txtCode).ToList
                        qryDelete(0).ISDELETE = 1

                    End If
                Next

                AMLOEntity.SaveChanges()

                IsDataBind()
                AMLOEntity = Nothing
                clearGvIndex()
            ElseIf (UserRight.getRoleGroup < 80) Then
                ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('ไม่มีสิทธิ์ลบรายการนี้')", True)
            End If

        Catch ex As Exception
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientScript", "alert('" + ex.Message + "')", True)
        End Try

    End Sub

    Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        If Not (grdAmlo.SelectedIndex = -1) Then
            Dim txtCode As String = CType(grdAmlo.Rows(grdAmlo.SelectedIndex).FindControl("hdfRptSeq"), HiddenField).Value
            Dim param As String = "{ 'RPTSEQ' : '" & txtCode & "','RPTTYPE' : '" & "3" & "'}"
            SaveLogPrint(2)
            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('frmPopupSelectPrint.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)
            '  Next
        Else
            Dim param As String = "{ 'RPTSEQ' : '" & "" & "','RPTTYPE' : '" & "3" & "'}"

            ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType, "key", "OpenWindowWithPost('frmPopupSelectPrint.aspx','width=730,height=345,left=100,top=100,resizable=yes,scrollbars=yes','Report', " + param + ");", True)

        End If


    End Sub

    Private Sub SaveLogSearch()
        Try
            clsSessionMenuRight = Session("ClsMenuRight")
            Dim desc As String = ""



            If Not (ddlBranch.SelectedValue = "0") Then
                desc += " ส่วนงาน/สาขา - " + ddlBranch.SelectedItem.Text
            End If

            If Not (txtDateStart.Text = "") And Not (txtDateEnd.Text = "") Then
                desc += " วันที่ทำธุรกรรม - " + txtDateStart.Text + " ถึง " + txtDateEnd.Text
            End If


            If Not desc = "" Then
                desc = "ค้นหาข้อมูลผู้ใช้งานระบบ จาก " + desc
            Else
                desc = "ค้นหาทั้งหมด "
            End If

            If rdoDelete.Visible = True Then
                If rdoDelete.SelectedValue = -1 Then
                    desc += " สถานะการยืนยัน - " + "ทั้งหมด "
                ElseIf rdoDelete.SelectedValue = 1 Then
                    desc += " สถานะการยืนยัน - " + "ยืนยัน "
                ElseIf rdoDelete.SelectedValue = 2 Then
                    desc += " สถานะการยืนยัน - " + "ไม่ยืนยัน "
                ElseIf rdoDelete.SelectedValue = 0 Then
                    desc += " สถานะการยืนยัน - " + "ยังไม่ตอบ "
                End If
            End If

            If ChkIsDelete.Visible = True Then
                If ChkIsDelete.Checked = True Then
                    desc += " สถานะการลบ - " + "ขอลบ "
                End If
            End If

            Dim clsLogTransaction As New clsLogTransaction
            clsLogTransaction.saveLogTransaction("", clsSessionMenuRight.getUserName, 1, desc, "M57")
            clsLogTransaction = Nothing
        Catch ex As Exception
            Throw ex
        End Try

    End Sub

    Protected Sub chkAllDel_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        Dim chk As CheckBox = CType(grdAmlo.HeaderRow.FindControl("chkAll_Del"), CheckBox)
        If (chk.Checked) Then
            For i As Int16 = 0 To grdAmlo.Rows.Count - 1
                Dim chkrow As CheckBox = CType(grdAmlo.Rows(i).FindControl("CheckBox1"), CheckBox)
                If (chkrow.Enabled) Then
                    chkrow.Checked = True
                End If
            Next
        Else

            For i As Int16 = 0 To grdAmlo.Rows.Count - 1
                Dim chkrow As CheckBox = CType(grdAmlo.Rows(i).FindControl("CheckBox1"), CheckBox)
                If (chkrow.Enabled) Then
                    chkrow.Checked = False
                End If
            Next

        End If
    End Sub

    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ddlBranch.SelectedIndex = 0
        ddlTransType.SelectedIndex = 0
        txtDateStart.Text = ""
        txtDateEnd.Text = ""
        rdoDelete.SelectedValue = -1

        lblMsg.Visible = False
        lblTotal.Text = ""

        grdAmlo.DataSource = Nothing
        grdAmlo.DataBind()

        clsSessionMenuRight = Session("ClsMenuRight")
        setDefaultSearch()
    End Sub
#End Region

End Class
